package com.hilon.segment.mybatis.utils;

import lombok.Data;
import org.springframework.stereotype.Component;

@Component
@Data
public class ResultBean<T> {
    private T resultData;
    private int code = SUCCESS;
    private String msg = "成功!";

    public static final int SUCCESS = 200;

    // TODO 这里要改, 所有的异常都要用正确的代码来表示.
    // 未知错误
    public static final int UNKNOWN_EXCEPTION = -99;

    // 用户状态异常
    public static final int NOT_LOGIN = 100;
    public static final int UNAUTHORIZED = 101;
    public static final int LOGIN_FAILED = 102;
    public static final int NOT_EXIST_USER = 103;
    public static final int EXIST_USER = 104;
    public static final int CODE_WRONG = 105;

    // 数据库异常
    public static final int SQL_CHANGE_WRONG = 301;
    public static final int SQL_QUERY_WRONG = 302;
    public static final int SQL_ROLLBACK_WRONG = 303;

    // 文件操作异常
    public static final int FILE_READ_WRONG = 501;
    public static final int FILE_WRITE_WRONG = 502;

    public ResultBean() {
        super();
    }

    public ResultBean(T resultData) {
        super();
        this.resultData = resultData;
    }

    public ResultBean(int code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }

    public ResultBean(T resultData, int code, String msg) {
        super();
        this.resultData = resultData;
        this.code = code;
        this.msg = msg;
    }

    public ResultBean(Throwable e) {
        super();
        this.code = UNKNOWN_EXCEPTION;
        this.msg = e.toString();
    }
}
